{include file='common/doc'}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="display: none;">
            <form  class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nickname" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text"  name="phone" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">访问日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="last_time" class="layui-input" id="last_time">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value=""></option>
                                <option value="1">启用</option>
                                <option value="0">警用</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table id="table_list" lay-filter="table_list"></table>
            <template id="table_toolbar">
                <div class="layui-btn-group">
                    <button type="button" lay-event="search_sh" class="layui-btn layui-btn-primary layui-btn-sm">
                        <i class="layui-icon layui-icon-search "></i>
                    </button>
                </div>
            </template>
        </div>
    </div>
</div>

<div style="display:none;padding-top:30px;" id="build_token" >
    <form action="" class="layui-form" style="padding-top:30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">token</label>
            <div class="layui-input-block">
                <input type="text" name="token" disabled placeholder="token" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
</body>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index' ,'table','laydate'] ,function () {
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#last_time' //指定元素
            ,range: true
        });
        table.render({
            elem: '#table_list'
            ,height: 'full-50'
            ,toolbar: '#table_toolbar'
            ,url: 'read' //数据接口
            ,page: true //开启分页
            ,limit:20
            ,cols: [
                [ //表头
                    {type: 'checkbox' ,fixed: 'left'}
                    ,{type: 'numbers' ,fixed: 'left'}

                    ,{field: 'back_cash' ,align: "center" ,title: '充值用户'}
                    ,{field: 'amount' ,align: "center" ,title: '充值',templet:function(d){
                        return d.back_phone+'充值'+d.amount+'元';
                    }}
                    ,{field: 'get_cash' ,align: "center" ,title: '返回用户'}
                    ,{field: 'cash_back' ,align: "center" ,title: '返现佣金',templet:function(d){
                        return d.get_phone+'返现'+d.cash_back+'元';
                    }}

                ]
            ]
        });
        //头工具栏事件
        table.on('toolbar(table_list)' ,function (obj) {
            let event = obj.event;
            var checkStatus = table.checkStatus(obj.config.id);
            if (event == 'search_sh') {
                $('.layui-card-header').toggle('slow');
            }
        });

        table.on('tool(table_list)' ,function (obj) {
            function update(field){
                $.ajax({
                    url:'upd',
                    data:field,
                    async:false,
                    method:'post',
                    success:function(x){
                        if (x['code']  !=0){
                            layer.msg(x['msg']);
                        }else{
                            layer.msg(x['msg']);
                        }
                    }
                })
            }
            let event = obj.event;
            if (event=='status'){
                    let field = {
                        'member_id':obj.data['member_id'],
                        'status':(obj.data['status']  ? 0: 1)
                    };
                    console.log(field);
                    update(field);
            }
            if (event == 'edit') {
                layer.open({
                    type: 1 ,
                    title: '用户编辑' ,
                    area: ['auto'] ,
                    content: $('#form_template_edit').html() ,
                    success: function (lay ,index) {
                        form.render();
                        form.val('form' ,obj.data);
                        form.on('submit(form_submit)' ,function (res) {
                            res.field['admin_id'] = obj.data['admin_id'];
                            $.post('upd' ,res.field ,function (res) {
                                if (res.code !== 0) {
                                    layer.msg(res.msg);
                                } else {
                                    layer.msg(res.msg);
                                    layer.close(record);
                                    table.reload('table_list');
                                }
                            });
                            return false;
                        });
                    }
                })
            }

            if (event == 'del') {
                $.post('del' ,obj.field ,function (res) {
                    obj.del();
                    layer.msg(res.msg);
                });
            }
            if(event=='build_token'){
                layer.open({
                    type:1,
                    title:false,
                    area:['500px'],
                    content:$('#build_token').html(),
                    success:function(lay,index){
                        $.ajax({
                            url:'build_token',
                            data:{'member_id':obj.data['member_id']},
                            method:'post',
                            async:false,
                            success:function(token){
                                if (token['code']  !=0){
                                   layer.msg(token['msg']);
                                }else{
                                    lay.find('input[name=token]').val(token['token']);
                                }
                            }
                        })
                    }
                })

            }
        });
        /*搜索*/
        form.on('submit(search)' ,function (obj) {
            table.reload('table_list' ,{
                method: 'get' ,
                where: {where:obj.field},//设定异步数据接口的额外参数

            });
            return false;
        });
    });
</script>
</html>

